<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>生产查询</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../css/public.css" media="all">
		<style>
			.layui-layer-page {
			padding: 10px !important;
		}
	</style>
	</head>

	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">
				<!--搜索开始-->
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="" id="searchFrm">
							<div class="layui-form-item">
								<!-- <div class="layui-inline">
									<label class="layui-form-label">查询时间</label>
									<div class="layui-input-inline">
										<div class="layui-input-inline">
											<input type="text" name="registerTime" id="register_time" readonly="readonly" autocomplete="off" class="layui-input">
										</div>
									</div>
								</div> -->
								<div class="layui-inline">
									<label class="layui-form-label">工序名称</label>
									<div class="layui-input-inline">
										<div class="layui-input-inline">
											<input type="text" name="procedure_name" id="procedure_name" class="layui-input">
										</div>
									</div>
								</div>
								<!-- <div class="layui-inline">
									<label class="layui-form-label">审核状态</label>
									<div class="layui-input-inline">
										<select name="check_tag">
											<option value="">请选择审核状态</option>
											<option value="S001-1">等待审核</option>
											<option value="S001-2">审核通过</option>
											<option value="S001-3">审核不通过</option>
										</select>
									</div>
								</div> -->
							</div>
							<div class="layui-form-item">
								<div class="layui-block" style="text-align: center;">
									<a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
									<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label
										 class="layui-icon layui-icon-refresh"></label>重置</a>
								</div>
							</div>
						</form>
					</div>
				</fieldset>
				<!--搜索结束-->

				<!--表格开始-->
				<table class="layui-hide" id="RecordTable" lay-filter="RecordTable"></table>
				<!-- <div style="display: none;" id="RecordToolBar">
					<a class="layui-btn layui-btn-sm inport_btn_add" lay-event="add">添加</a>
				</div> -->
				<div style="display: none;" id="RecordTableBar">
					<a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete inport_btn_see" lay-event="see">查看详情信息</a>
					<!-- <a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete inport_btn_update" lay-event="update">修改</a>
					<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete inport_btn_delete" lay-event="delete">删除</a>
					<a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete inport_btn_back" lay-event="back">退货</a> -->
				</div>
				<!--表格结束-->
				
				<!-- 详情数据 -->
				<div id="seeRecord" style="display: none;padding: 0.3125rem;">
					<form method="post" class="layui-form layui-form-pane" lay-filter="Record" id="Record">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">序号:</label>
								<div class="layui-input-inline">
									<input type="text" name="id" id="id" lay-verify="required|id" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">工序序号:</label>
								<div class="layui-input-inline">
									<input type="text" name="detailsNumber" id="detailsNumber" lay-verify="required|detailsNumber" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">工序编号:</label>
								<div class="layui-input-inline">
									<input type="text" name="procedureId" id="procedureId" lay-verify="required|procedureId" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">工序名称:</label>
								<div class="layui-input-inline">
									<input type="text" name="procedureName" id="procedureName" lay-verify="required|procedureName" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">本次工时数:</label>
								<div class="layui-input-inline">
									<input type="text" name="labourHourAmount" id="labourHourAmount" lay-verify="required|labourHourAmount" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">单位工时成本:</label>
								<div class="layui-input-inline">
									<input type="text" name="costPrice" id="costPrice" lay-verify="required|costPrice" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">工时成本小计:</label>
								<div class="layui-input-inline">
									<input type="text" name="subtotal" id="subtotal" lay-verify="required|subtotal" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">登记次数:</label>
								<div class="layui-input-inline">
									<input type="text"  name="regCount" lay-verify="required|regCount" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">登记人:</label>
								<div class="layui-input-inline">
									<input type="text" name="register" id="register" lay-verify="required|register" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">登记时间:</label>
								<div class="layui-input-inline">
									<input type="text" name="registerTime" id="registerTime" lay-verify="required|registerTime" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">复核时间:</label>
								<div class="layui-input-inline">
									<input type="text" name="checkTime" id="checkTime" lay-verify="required|checkTime" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">审核标志:</label>
								<div class="layui-input-inline">
									<input type="text" name="checkTag" lay-verify="required|checkTag" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">审核人:</label>
								<div class="layui-input-inline">
									<input type="text" name="checker" lay-verify="required|checker" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="" style="text-align: center;">
								<!-- <a class="layui-btn layui-btn-sm" lay-submit="" lay-filter="doSubmit"><label class="layui-icon layui-icon-release"></label>提交</a>
								<a class="layui-btn layui-btn-sm layui-btn-warm" onclick="javascript:$('#plandata')[0].reset()" lay-filter="data-search-btn"><label
									 class="layui-icon layui-icon-refresh"></label>重置</a> -->
								<a class="layui-btn layui-btn-sm layui-btn-warm" lay-submit="" lay-filter="close" lay-filter="data-search-btn">
									<label class="layui-icon layui-icon-close"></label>关闭
								</a>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
		<script src="../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../lib/common/common.js" charset="utf-8"></script>

		<script>
			layui.use(['form', 'table', 'laydate', 'layer'], function() {
				var form = layui.form;
				var table = layui.table;
				var laydate = layui.laydate;
				var layer = layui.layer;

				//渲染时间选择器
				laydate.render({
					elem: '#register_time',
					type: 'datetime'
				});
				// laydate.render({
				// 	elem: '#endTime',
				// 	type: 'datetime'
				// });

				// //加载查询条件里面的供应商的下拉列表
				// $.get(api6 + "provider/getAllAvailableProvider", function(res) {
				// 	var search_providerid = $(".providerSel");
				// 	var html = "<option value =''>请选择供应商</option>";
				// 	var data = res.data;
				// 	$.each(data, function(index, item) {
				// 		// 注入供应商ID 和 名称
				// 		html += "<option value =" + item.id + ">" + item.providername + "</option>"
				// 	});
				// 	search_providerid.html(html);
				// 	// 重载下拉框
				// 	form.render("select");
				// });


				// //加载查询条件里面的商品的下拉列表
				// $.get(api6 + "goods/getAllAvailableGoods", function(res) {
				// 	var search_goodsid = $(".goodsSel");
				// 	var html = "<option value =''>请选择商品</option>";
				// 	var data = res.data;
				// 	$.each(data, function(index, item) {
				// 		// 注入商品ID 和 名称
				// 		html += "<option value =" + item.id + ">" + item.goodsname + "--[" + item.size + "]" + "</option>"
				// 	});
				// 	search_goodsid.html(html);
				// 	// 重载下拉框
				// 	form.render("select");
				// });


				var tableIns = table.render({
					elem: '#RecordTable',
					url: api6 + 'record/selAllRecord',
					toolbar: "#RecordToolBar",
					cellMinWidth: true,
					cols: [
						[{
								field: 'id',
								title: 'ID',
								align: "center",
								width: 250
							},
							{
								field: 'procedureId',
								title: '工序编号',
								align: "center",
								width: 150
							},
							{
								field: 'procedureName',
								title: '工序名称',
								align: "center",
								width: 133
							},
							{
								field: 'regCount',
								title: '登记次数',
								align: "center",
								width: 150
							},
							{
								field: 'labourHourAmount',
								title: '本次工时数',
								align: "center",
								width: 150
							},
							{
								field: 'costPrice',
								title: '单位工时成本',
								align: "center",
								width: 150
							},
							{
								field: 'register',
								title: '登记人',
								align: "center",
								width: 150
							},
							{
								field: 'registerTime',
								title: '登记时间',
								align: "center",
								width: 150
							},
							{
								field: 'checker',
								title: '审核人',
								align: "center",
								width: 150
							},
							{
								field: 'checkTime',
								title: '审核时间',
								align: "center",
								width: 150
							},
							{
								title: '操作',
								templet: '#RecordTableBar',
								fixed: "right",
								align: "center",
								width: 180
							}
						]
					],
					page: true
				});

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var params = $("#searchFrm").serialize();
					console.log(params);
					//执行搜索重载
					table.reload('RecordTable', {
						page: {
							curr: 1
						},
						url: api6 + 'record/selAllRecord?' + params
					});
					return false;
				});

				//监听表头的事件
				table.on('toolbar(RecordTable)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case 'add':
							openAddInport();
							break;
					};
				});

				//监听添加弹出层里面的 供应商   的下拉改变事件
				form.on("select(data_providerid)", function(obj) {
					// 获取供应商ID
					var providerid = obj.value;
					// 获取商品下拉框
					var goodsDataSel = $(".goodsDataSel");
					initGoodsSeleted(providerid, goodsDataSel)
				})

				// 初始化下拉框 两级联动
				/**
				 *  providerid  供应商id
				 *  elem		商品下拉框
				 *  fun			回调函数
				 */
				function initGoodsSeleted(providerid, elem, fun) {
					var html = "<option value =''>请选择商品</option>";
					if (providerid != "") {
						// 根据供应商ID 查询商品
						$.get(api6 + "goods/getGoodsByProviderId", {
							providerid: providerid
						}, function(res) {
							var data = res.data;

							$.each(data, function(i, item) {
								// 进行追加数据
								html += "<option value =" + item.id + ">" + item.goodsname + "[" + item.size + "]" + "</option>"
							});

							// 覆盖到 elem  html内容当中
							elem.html(html);

							// 重载下拉框
							form.render("select");

							// 进行回调数据    
							if (fun != undefined) {
								fun();
							}
						});
					} else {
						elem.html(html);
						form.render("select");
					}
				}


				//监听行数据的事件
				table.on('tool(RecordTable)', function(obj) {
					var data = obj.data;
					if (obj.event === 'delete') {
						layer.confirm('真的删除这条进货数据么', function(index) {
							$.post(api6 + "inport/deleteInport", {
								id: data.id
							}, function(res) {
								layer.msg(res.msg);
								obj.del();
								layer.close(index);
							})
						});
					} else if (obj.event === 'update') {
						openUpdateInport(data);
					} else if (obj.event === 'back') {
						openBack(data);
					}else if (obj.event === 'see') {
						seeRecord(data.id);
					}
				});

				//打开添加进货的弹层
				var mainIndex;
				var url; //动态的url
				function openAddInport() {
					mainIndex = layer.open({
						type: 1,
						title: '添加进货',
						content: $("#addOrUpdateDiv"),
						area: ['675px', '407px'],
						success: function(index) {
							$("#data_providerid").attr("disabled", false);
							$("#data_goodsid").attr("disabled", false);
							url = api6 + "inport/addInport";
							//重置表单
							$("#dataFrm")[0].reset();

						}
					});
				}
				
				form.on("submit(close)", function(data) {
					// 序列化
				// 	var params = $("#backDataFrm").serialize();
				
				// 	$.post(api6 + "outport/addOutport", params, function(res) {
				// 		layer.msg(res.msg);
				// 		if (res.code == 200) {
				// 			tableIns.reload();
				// 		}
						layer.close(mainIndex);
				// 	})
				// 	return false;
				});

// 修改进货 
				function seeRecord(data) {
					mainIndex = layer.open({
						type: 1,
						title: '查看详情信息',
						content: $("#seeRecord"),
						area: ['1000px', '457px'],
						success: function(index) {


							// layer.tips('需要修改进货数量直接覆盖数量即可', '#numbers', {
							// 	tips: 1
							// });

							$.get(api6 + "record/selByIdRecord?id="+data, function(res) {
									console.log(res);
									// alert(res.productname);
									if(res.checkTag= "S001-1"){
										res.checkTag= "等待审核";
									}else if(res.checkTag= "S001-2"){
										res.checkTag= "审核通过";
									}else if(res.checkTag= "S001-3"){
										res.checkTag= "审核不通过";
									}else{
										res.checkTag= "错误数据";
									}
									// //用途类型
									// if(res.type= "Y001-1"){
									// 	res.type= "商品";
									// }else{
									// 	res.type= "物料";
									// }
									// //派工标志
									// if(res.manufactureTag= "P001-1"){
									// 	res.manufactureTag= "已派工";
									// }else{
									// 	res.manufactureTag= "未派工";
									// }
									// res.dj=res.costPriceTotal/res.amount;
									form.val("Record", res);
							})
							form.render();
						}
					});
				}

				
				


				//提交数据
				form.on("submit(doBack)", function(data) {
					// 序列化
					var params = $("#backDataFrm").serialize();

					$.post(api6 + "outport/addOutport", params, function(res) {
						layer.msg(res.msg);
						if (res.code == 200) {
							tableIns.reload();
						}
						layer.close(mainIndex);
					})
					return false;
				});

				form.verify({
					checkgoodsnumber: function(value, item) { //value：表单的值、item：表单的DOM对象
						var str;
						var goodsid = $("#back_goodsid").val();
						$.ajax({
							//  获取商品的数量  
							url: api6 + "goods/getGoodsByGoodId?goodsid=" + goodsid,
							type: 'get',
							async: false,
							success: function(res) {
								//  判断 商品 的数量 是否大于我要 退货的  数量  
								// 大于则违反逻辑
								if (res.data.number < value) {
									str = "退货数量不能大于当前商品库存";
								}
							}
						})
						return str;
					}
				});
			});
		</script>
		
		<script type="text/html" id="TcheckTag">
					{{# if(d.checkTag=='S001-1'){d.checkTag='等待审核'}}
						{{d.checkTag}}
					{{# }else if(d.checkTag=='S001-2'){d.checkTag='审核通过'}}
						{{d.checkTag}}
					{{# }else{d.checkTag='审核不通过'}}
						{{d.checkTag}}
					{{# }}}
		</script>
		<script type="text/html" id="ManufactureTag">
					{{# if(d.checkTag=='P001-1'){d.checkTag='未派工'}}
						{{d.checkTag}}
					{{# }else{d.checkTag='已派工'}}
						{{d.checkTag}}
					{{# }}}
		</script>

	</body>

</html>
